package com.briup.bms.web.controller;

import com.briup.bms.bean.SCustomer;
import com.briup.bms.bean.SProduct;
import com.briup.bms.common.utils.Result;
import com.briup.bms.service.SCustomerService;
import com.briup.bms.service.SProductService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Set;

/**
 * @author: Paocha
 * @date: 2021-11-23-15:49
 */
@Api(tags = "产品信息服务")
@RestController
@RequestMapping("/product")
public class ProductController {


    private final SProductService productService;


    public ProductController(SProductService productService) {
        this.productService = productService;
    }

    @ApiOperation(value = "按条件分页显示客户信息")
    @GetMapping("/by/condition")
    public Result<PageInfo<SProduct>> findByCondition(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize,
            String name) {

        return Result.success(productService.findByConditon(
                pageNum, pageSize, name));
    }

    @GetMapping("")
    public Result<PageInfo<SProduct>> findByPageHelper(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize) {

        return Result.success(productService.findByPageHelper(
                pageNum, pageSize));
    }

    @PostMapping
    public Result<String> saveOrUpdate(@RequestBody SProduct product) {
        //业务处理
        productService.saveOrUpdate(product);
        return Result.success("操作成功！");
    }

    @DeleteMapping("/{productId}")
    public Result<String> deleteProduct(@PathVariable("productId") Integer productId) {
        productService.deleteCustomer(productId);
        return Result.success("删除"+productId+"成功");
    }
    @DeleteMapping("/batchDelete")
    public Result<String> batchDeleteProduct(@RequestParam("productIds") Set<Integer> productIds) {
        productService.batchDeleteCustomer(productIds);
        return Result.success("删除"+ productIds +"成功");
    }
}
